$ = function(name) {
	return document.getElementById(name);
};
$N = function(name) {
	return document.getElementsByName(name);
};
getRV = function (xml){
	try{
		if(xml.getElementsByTagName("root")[0].getAttribute("value")=="true")
			return true;
	}catch(e){return false;}
	return false;
}
checklogin = function(xml){
	try{
		if(xml.getElementsByTagName("root")[0].getAttribute("value")=="notlogin" || xml.text=="notlogin")
			return false;
	}catch(e){return true;}
	return true;
}
function trim(str){
	str = str.replace(/^\s+/, '');
	for (var i = str.length; i>=0;i--)
	if (/\S/.test(str.charAt(i)))
	return str.substring(0, ++i)
	return str
};
$C = function(name, type, value)
{
	var o = document.createElement(name);
	if(o){
		if(type) {
			o.type = type;
			if(value){ o.value = value;}
		}
		else if(value){ o.innerHTML = value;}
		return o;
	}
	throw ("Cannot create object. Message from $C funtion");
};
function checkCatId(id){
	var s = id.split(",");
	var l = $N("cat");
	for(var i=0; i < s.length; i++){
		for(var j=0; j < l.length; j++){
			if($N("cat")[j].value==s[i]){
				$N("cat")[j].checked = true;
				break;
			}
		}
	}
}
function getCheckCatId(){
	var l = $N("cat");
	var catid = "";
	for(var j=0; j < l.length; j++){
		if($N("cat")[j].checked ==true)
			catid += $N("cat")[j].value+",";
	}
	if(catid!="") catid = catid.substring(0,catid.length-1);
	return catid;
}

function textToArea(str){
	if(str==null||str=="") return "";
	return str.replace(/<br>/g,"\n").replace(/<br\/>/g,"\n").replace(/&lt;br\/&gt;/g,"\n").replace(/&lt;/g,"<").replace(/&gt;/g,">");
}
function parseIMG(id,filepic){
	return $LINKDATA+"/"+id.substring(0,6)+"/"+id+"/"+filepic;
}
function dateSQLtoN(d){
	try{
		var dd = d.split(" ")[0];
		return dd.split("-")[2]+"/"+dd.split("-")[1]+"/"+dd.split("-")[0];
	}	catch(e){return "";}
}
function fulldateSQLtoN(d){
	try{
		var dd = d.split(" ")[0];
		var hh = d.split(" ")[1];
		return dd.split("-")[2]+"/"+dd.split("-")[1]+"/"+dd.split("-")[0]+" "+hh.split(":")[0]+":"+hh.split(":")[1];
	}	catch(e){return "";}
}
function getParam(){
	var param = window.location.search;
	var h=Array();

	if(param!=null&&param!=""){
		param = param.substring(1);
		var l = param.split("&");
		for(var i=0;i<l.length;i++){
			h[l[i].split("=")[0]]=decodeURIComponent(l[i].split("=")[1]).replace(/\+/g, ' ').replace(/\&amp;/g, '&');;
		}
	}
	return h;
}

function showDiv(id){
	$("fixed_div").style.height=screen.availHeight+"px";
	$("fixed_div").style.width=screen.availWidth+"px";
	$("fixed_div").style.display="block";
	var w = $(id).style.width.replace("px","");
	var h = $(id).style.height.replace("px","");	
	
	var width = screen.availWidth/2-w/2;
	var height = screen.availHeight/2-(h)/2;
	setPos(id,height,width);
	$(id).style.display="block";
//	var element = document.getElementById(id);
//    element.style.top = (document.documentElement.scrollTop + 20) + 'px';
	
	
}
function hideDiv(id){
	$("fixed_div").style.display="none";
	$(id).style.display="none";
}
function setPos(id,top_,left_){
	$(id).style.left=left_+"px";
	$(id).style.top=top_+"px";
}
function findPos(obj) {
	var curleft=0; var curtop=0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while ((obj=obj.offsetParent));
	}
	return [curleft,curtop];
};
function genLinkImg(newsid,filename){
	var first = newsid.substring(newsid.length-2,newsid.length-1);
	var middle = newsid.substring(newsid.length-3,newsid.length-2);
	return	$LINKDATA+"/"+first+"/"+middle+"/"+filename;
}
function makeLinkViewNews(lid,title){
	return "http://tn.rolo.vn/tn/chi-tiet/"+lid+"/"+title+"/";
}
function genLinkClip(clipId,filename){
	var first = clipId.substring(clipId.length-2,clipId.length-1);
	var middle = clipId.substring(clipId.length-3,clipId.length-2);
	return	$LINKDATA+"/clip/"+first+"/"+middle+"/"+filename;
}